﻿using System;
using System.Windows;
using System.Windows.Input;

namespace Auktionshuset.UserControls
{
    public partial class AuctionListViewItem
    {
        public delegate void ClickEvent(object sender, EventArgs e);

        public event ClickEvent Click;

        private bool _mouseDown;
        private Auction _auction;
        public Auction Auction
        {
            get
            {
                return _auction;
            }
            set
            {
                _auction = value;
                Title.Text = _auction.Title;
                Description.Text = _auction.Description;
            }
        }

        public AuctionListViewItem(Auction auction)
        {
            InitializeComponent();

            Auction = auction;
        }

        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            SelectedBorder.Visibility = Visibility.Visible;
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            SelectedBorder.Visibility = Visibility.Hidden;
            _mouseDown = false;
        }

        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (_mouseDown && Click != null)
            {
                _mouseDown = false;
                Click(this, e);
            }
        }

        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _mouseDown = true;
        }
    }
}
